package com.erp.ae.controller;

import com.erp.ae.utils.AeApiUtils;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldController.BaseController;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ae/auth")
public class AeAuthController extends BaseController {

    @GetMapping("/getAccessToken")
    public R<Object> getAccessToken(Long storeId, String code) {

        String responseBody = AeApiUtils.auth(storeId, code);
        return R.ok("", responseBody);
    }

    @GetMapping("/getAccessTokenInfo/{storeId}/{code}")
    public R<Object> getAccessTokenInfo(@PathVariable("storeId") Long storeId, @PathVariable("code") String code) {
        String responseBody = AeApiUtils.auth(storeId, code);
        return R.ok("", responseBody);
    }

    @GetMapping("/getToken")
    public R<Object> getToken(Long storeId, String code) {

        String responseBody = AeApiUtils.getToken(storeId);
        return R.ok("", responseBody);
    }

    @GetMapping("/getTokenByStoreId")
    public R<Object> getTokenByStoreId(Long storeId) {

        String responseBody = AeApiUtils.getToken(storeId);
        return R.ok("", responseBody);
    }


    @GetMapping("/setToken")
    public R<Object> setToken(String res, Long id) {
        return R.ok(AeApiUtils.setToken(res, id));
    }


}
